package com.jia.together.controller;

import com.jia.together.entity.MemberBlog;
import com.jia.together.service.MemberBlogService;
import com.jia.together.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dujiajia
 * @since 2021-02-19
 */
@RestController
@RequestMapping("/memberBlog")
public class MemberBlogController {

    @Autowired
    private MemberBlogService memberBlogService;

    @GetMapping("/list")
    public R list(@RequestParam("pageNum") Long pageNum,@RequestParam("pageSize") Long pageSize){
        Map<String,Object> map = memberBlogService.selectPageList(pageNum,pageSize);
        return R.ok().data(map);
    }
    @GetMapping("/info/{id}")
    public R info(@PathVariable String id){
        MemberBlog memberBlog = memberBlogService.getById(id);
        return R.ok().data("data",memberBlog);
    }
    @PostMapping("/add")
    public R add(@RequestBody MemberBlog memberBlog){
        memberBlogService.save(memberBlog);
        return R.ok();
    }

    @PutMapping("/update")
    public R update(@RequestBody MemberBlog memberBlog){
        memberBlogService.updateById(memberBlog);
        return R.ok();
    }
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable String id){
        memberBlogService.removeById(id);
        return R.ok();
    }

}

